package com.cloudweb.oa.controller;

import com.alibaba.fastjson.JSONObject;
import com.cloudweb.oa.service.MyflowService;
import com.cloudweb.oa.vo.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(tags = "流程图")
@Controller
@RequestMapping("/myflow")
public class MyflowController {

    @Autowired
    private MyflowService myflowService;

    @ApiOperation(value = "生成流程图描述字符串", notes = "生成流程图描述字符串", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "flowJson", value = "流程描述JSON", required = true, dataType = "String"),
            @ApiImplicitParam(name = "serverName", value = "服务器名称（暂无用）", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @ResponseBody
    @RequestMapping(value = "/generateFlowString", method = RequestMethod.POST, produces={"text/html;charset=UTF-8", "application/json;charset=UTF-8"})
    public String generateFlowString(@RequestParam(value = "flowJson") String flowJson, @RequestParam(value = "serverName") String serverName) {
        return myflowService.generateFlowString(flowJson, serverName).toString();
    }

    @ApiOperation(value = "生成流程图描述字符串", notes = "生成流程图描述字符串", httpMethod = "POST")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "flowJson", value = "流程图描述json", required = true, dataType = "String"),
        @ApiImplicitParam(name = "serverName", value = "服务器名称（暂无用）", required = false, dataType = "String"),
    })
    @ApiResponses({ @ApiResponse(code = 200, message = "操作成功") })
    @ResponseBody
    @RequestMapping(value = "/generateWorkflowString", method = RequestMethod.POST, produces={"text/html;charset=UTF-8", "application/json;charset=UTF-8"})
    public Result<Object> generateWorkflowString(@RequestParam(value = "flowJson") String flowJson, @RequestParam(value = "serverName") String serverName) {
        return new Result<>(myflowService.generateFlowString(flowJson, serverName));
    }
}
